import store from '@/store/index.js';
import {Toast} from 'vant';
export default function () {
    return new Promise((resolve, reject) => {
        let token = localStorage.getItem("token")
        let tokenExpired = localStorage.getItem("tokenExpired")
      
        if (token) {
            let now = new Date().getTime();
            if (now >= Number(tokenExpired)) {
                // token过期了
                localStorage.removeItem('token')
                localStorage.removeItem('tokenExpired')
                Toast('您的身份认证已过期，请重新登录')
                resolve()

            } else {
                Toast.loading({
                    message: '加载中...',
                    forbidClick: true,
                });
                store.dispatch('getuserInfo', token)
                .then((res) => {
             

                    resolve()


                    Toast.clear()

                }).catch((err)=>{
                    reject()
                })
            }

          

        } else {
           resolve()

        }

    })
}